/**
* This file is part of JizyEjb.
*
*    Nome-Programma is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    Nome-Programma is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with  JizyEjb.  If not, see <http://www.gnu.org/licenses/>.
*   
*    Copyright 2013 user    
*/
package com.tabuto.jizy.dao.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

import com.tabuto.jizy.dao.UserDao;
import com.tabuto.jizy.models.AbstractUser;

/**
 * @author user
 *
 */
public class UserJDBCDao extends AbstractJDBCDao implements UserDao {

	/* (non-Javadoc)
	 * @see com.tabuto.jizy.dao.UserDao#saveUser(com.tabuto.jizy.models.AbstractUser)
	 */
	@Override
	public boolean saveUser(AbstractUser user) {
		int result = 0;
		try{
			Connection c = getConnection();
			
			
			PreparedStatement pstat  = 
					c.prepareStatement(
							JDBCConstant.SQL_P_INSERT_USER);
			
			pstat.setString(1, user.getUsername());
			pstat.setString(2, user.getPassword());
			result = pstat.executeUpdate();
			c.commit();
			c.close();
		} catch (Exception e){
			throw new RuntimeException("An error occours on UserSqliteDao.saveUser: "+e.getMessage(),e);
		}
		return (result==1);
	}

	/* (non-Javadoc)
	 * @see com.tabuto.jizy.dao.UserDao#getUser(java.lang.String, java.lang.String)
	 */
	@Override
	public AbstractUser getUser(String username, String password) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.tabuto.jizy.dao.UserDao#validateUser(com.tabuto.jizy.models.AbstractUser)
	 */
	@Override
	public boolean validateUser(AbstractUser user) {
		// TODO Auto-generated method stub
		return false;
	}

}
